import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { DropDownBox, Form, Popup, SelectBox, TextBox } from "devextreme-react";
import React, { useCallback, useImperativeHandle, useRef } from "react";
import { useState } from "react";
import { SimpleItem } from "devextreme-react/form";
import { CpasIcon } from "~/public/cpas-ui";
import ReportPopup from "../../ReportPopup";
import PTextBox from "../PTextBox";
const items = [
    {
        id: "0",
        name: "借",
    },
    {
        id: "1",
        name: "贷",
    },
];
const EditSubjectsPopup = React.forwardRef((props, ref) => {
    const { AccountDataID, dbname } = props;
    const diaParams = useRef();
    const projectValueRef = useRef();
    const statementProjectRef = useRef();
    const [visible, setVisible] = useState(false);
    const [SelectType, setSelectType] = useState("");
    const [SelectName, setSelectName] = useState("");
    const [selectedYears, setSelectedYears] = useState("");
    const [SubjectNumbers, setSubjectNumber] = useState("");
    function subjectFx() {
        let typeDatas = items.filter((item) => {
            return item.name.includes(diaParams.current?.args.subjectFx);
        });
        setSelectName(typeDatas[0].name);
    }
    // 自定义方法
    useImperativeHandle(ref, () => ({
        show: async (params) => {
            diaParams.current = params;
            setVisible(true);
            setSubjectNumber(diaParams.current?.args?.KMMC);
            setSelectType(diaParams.current?.args.Typename[0].type);
            subjectFx();
        },
        close: () => {
            setVisible(false);
        },
    }));
    const onOk = useCallback(() => {
        const SubjectNumber = projectValueRef.current || diaParams.current?.args?.KMMC;
        if (diaParams.current?.okCallback) {
            diaParams.current?.okCallback({
                SubjectNumber,
                SelectName,
                SelectType,
                selectedYears,
            }, "");
            setSelectedYears("");
        }
        setVisible(false);
    }, [SelectType, SelectName, selectedYears]);
    const onCancel = useCallback(() => {
        setVisible(false);
        setSelectedYears("");
        setSubjectNumber("");
        projectValueRef.current = "";
    }, []);
    // const onchanges = (e: any) => {
    //   const { event } = e;
    //   setSubjectNumber(event.target.value);
    // };
    return (_jsx(_Fragment, { children: _jsx(Popup, { ref: ref, visible: visible, title: diaParams.current?.args?.title, width: 630, height: 450, ...props, onHiding: () => {
                setVisible(false);
                setSelectedYears("");
            }, dragOutsideBoundary: true, resizeEnabled: true, toolbarItems: [
                {
                    widget: "dxButton",
                    toolbar: "bottom",
                    location: "after",
                    options: {
                        text: "取消",
                        onClick: () => onCancel(),
                    },
                },
                {
                    widget: "dxButton",
                    toolbar: "bottom",
                    location: "after",
                    options: {
                        text: "确定",
                        type: "default",
                        onClick: () => onOk(),
                    },
                },
            ], children: _jsxs(_Fragment, { children: [_jsxs(Form
                    // ref={refsForm}
                    // formData={formAllData}
                    , { 
                        // ref={refsForm}
                        // formData={formAllData}
                        colCount: 2, labelLocation: "left", labelMode: "outside", focusStateEnabled: true, showColonAfterLabel: true, alignItemLabels: true, className: "SubjectsForm", children: [_jsxs(SimpleItem, { colSpan: 2, dataField: "sjxmbh", editorType: "dxTextBox", label: { text: "上级科目" }, children: [_jsx(TextBox, { className: "TextBox_Style", readOnly: true, disabled: true, showClearButton: true, value: diaParams.current?.args?.ParentLevel }), _jsxs("span", { style: { position: "absolute", right: "3px", top: "6px" }, children: [_jsx(CpasIcon, { type: "icon-xinzengkemu" }), _jsx(CpasIcon, { type: "icon-close1" })] })] }), _jsx(SimpleItem, { colSpan: 2, dataField: "sjxmbh", editorType: "dxTextBox", editorOptions: {
                                    value: diaParams.current?.args?.KMBH,
                                    disabled: true,
                                }, label: { text: "科目编号" } }), _jsx(SimpleItem, { colSpan: 2, label: { text: "科目名称" }, children: _jsx(PTextBox, { defaultValue: SubjectNumbers, changeData: (data) => {
                                        projectValueRef.current = data;
                                        setSubjectNumber(data);
                                    } }) }), _jsx(SimpleItem, { colSpan: 2, label: { text: "科目方向" }, children: _jsx(SelectBox, { dataSource: items, value: SelectName ? SelectName : items[0].name, displayExpr: "name", valueExpr: "name", onSelectionChanged: (e) => {
                                        setSelectName(e.selectedItem.name);
                                    } }) }), _jsx(SimpleItem, { colSpan: 2, label: { text: "科目类型" }, children: _jsx(SelectBox, { dataSource: diaParams.current?.args.Typedata, value: SelectType, displayExpr: "type", valueExpr: "type", onSelectionChanged: (e) => {
                                        setSelectType(e.selectedItem.type);
                                    } }) }), _jsx(SimpleItem, { colSpan: 2, children: _jsx("div", { style: {
                                        width: "100%",
                                        borderBottom: "1px solid rgb(0,0,0,0.10)",
                                        height: "10px",
                                    } }) }), _jsxs(SimpleItem, { colSpan: 2, dataField: "sjxmbh", editorType: "dxTextBox", label: { text: "对应报表项目" }, children: [_jsx(DropDownBox, { className: "StatementDropDownBox", value: selectedYears, height: 32, displayExpr: "itemName", valueExpr: "itemName", disabled: true, placeholder: selectedYears.length > 0
                                            ? selectedYears.map((item) => item.itemName)
                                            : diaParams.current?.args.itemNames }), _jsxs("span", { style: { position: "absolute", right: "6px", top: "6px" }, children: [_jsx(CpasIcon, { type: "icon-xinzengkemu", onClick: () => {
                                                    statementProjectRef.current.show({
                                                        title: "选择报表项目",
                                                        dbname: dbname,
                                                        Data_ID: AccountDataID,
                                                        ownerReport: "",
                                                        selectMode: "1",
                                                        // 选择 模式 0：单选 1：多选连机选择
                                                        okCallback: (r) => {
                                                            setSelectedYears(r);
                                                        },
                                                    });
                                                } }), _jsx(CpasIcon, { type: "icon-close1", onClick: () => {
                                                    setSelectedYears("");
                                                } })] })] })] }), _jsx("div", { style: {
                            width: "100%",
                            display: "flex",
                            alignItems: "center",
                            justifyContent: "end",
                            marginTop: "10px",
                        }, children: _jsx("span", { style: { fontSize: "12px", color: "#666" }, children: "\u4E00\u7EA7\u6216\u5907\u62B5\u79D1\u76EE\u9700\u6307\u5B9A\u5BF9\u5E94\u62A5\u8868\u9879\u76EE" }) }), _jsx("div", { style: {
                            width: "100%",
                            height: "14px",
                            borderBottom: "1px solid rgb(0,0,0,0.10)",
                        } }), _jsx(ReportPopup, { ref: statementProjectRef })] }) }) }));
});
export default EditSubjectsPopup;
